package com.whu.zqm.dao;

import com.whu.zqm.entity.Products;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ProductsJPARepository extends JpaRepository<Products, Long>, JpaSpecificationExecutor<Products> {
    //直接使用Native Query
    List<Products> findByName(String name);

//    Products findById(long id);

    //通过jpql实现查询仍有剩余库存的商品
    @Query("select p from Products p where p.num > 0")
    List<Products> findProductsInStock();

    //Paging and Sorting
    Page<Products> findAll(Pageable pageable);


}
